package com.spring.mvc.service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.spring.mvc.bean.CanbLocal;
import com.spring.mvc.dao.CanbLocalMapper;
import com.spring.mvc.util.Constantes;




@Service
public class CanbLocalServiceImpl implements CanbLocalService{
		

	//@Resource(name = "clienteMapper")
	@Autowired
	private CanbLocalMapper canbLocalMapper;
	
	public CanbLocal selectByIdLocal(Integer idLocal) throws Exception {
		CanbLocal local=canbLocalMapper.selectByPrimaryKey(idLocal);
		return local;
	}

	public List<Map<String, Object>> selectAllLocal(String DES_LOCAL)
			throws Exception {
		Map<String,Object> params=new HashMap<String, Object>();

		if(DES_LOCAL !=null){
			params.put("DESLOCALLIKE",'%'+DES_LOCAL+'%');
		}else{
			params.put("DESLOCALLIKE",DES_LOCAL);
		}
		params.put("STLOCAL", Constantes.ESTADO_ACTIVO);
		
		List<Map<String, Object>> listaLocal=canbLocalMapper.selectAllLocal(params);

		return listaLocal;
	}

	public CanbLocal updatebyIdLocal(CanbLocal canbLocal) throws Exception {
		canbLocal.setFEC_MODIFICO(new Date());
		canbLocalMapper.updateByPrimaryKeySelective(canbLocal);
		canbLocal=canbLocalMapper.selectByPrimaryKey(canbLocal.getID_LOCAL());
		return canbLocal;
	}

	public int deleteByIdLocal(Integer idLocal) throws Exception {
		return canbLocalMapper.deleteByPrimaryKey(idLocal);
	}

	public CanbLocal insertLocal(CanbLocal canbLocal) throws Exception {
		canbLocal.setFEC_REGISTRO(new Date());
		canbLocal.setST_LOCAL(Constantes.ESTADO_ACTIVO);
		canbLocalMapper.insertSelective(canbLocal);
		return canbLocal;
	}

	public int selectCountAllLocal(String DES_LOCAL) throws Exception {
		Map<String,Object> params=new HashMap<String, Object>();
		
		if(DES_LOCAL !=null){
			params.put("DESLOCALLIKE",'%'+DES_LOCAL+'%');
		}else{
			params.put("DESLOCALLIKE",DES_LOCAL);
		}
		params.put("STLOCAL", Constantes.ESTADO_ACTIVO);
		Integer count=canbLocalMapper.selectCountAllLocal(params);
	return count;
	}
}
